$(function(){
    var nextButton = $('#nextButton');
    var msgBox = $('#tkyou');
    var win = $(window);
    
    var lastScrollTop = 0;
    
    $('.reply').live('click', LS.UI.replyClick);
    $('#autoSwitch').click(LS.UI.switchClick);
    $('#quote').click(LS.UI.quoteClick);
    nextButton.click(LS.UI.nextHomeTimeLineClick);
    $('#home-link').click(LS.UI.homeLinkClick);
    $('#updateSubmit').click(LS.UI.updateStatusClick);
    msgBox.click(LS.UI.msgboxClick);
    $(document.body).click(LS.UI.resetHome);
    setInterval(LS.UI.getNewTimeline, 1000 * 60);
    $('.autoupdate-switch-label').click(LS.UI.getNewTimeLine);
    
    // Auto load next page
    if (LS.Config.autoShowContent) {
        $(document).scroll(function() {
            var currentScrollTop = win.scrollTop();
            if (currentScrollTop > lastScrollTop && nextButton.offset().top - currentScrollTop < win.height()) {
                nextButton.click();
            }
            if (currentScrollTop < lastScrollTop && msgBox.offset().top > currentScrollTop) {
                msgBox.click();
            }
            lastScrollTop = currentScrollTop;
        });
    }
});
